﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Nancy;
using Nancy.Json;
using System.IO;
using System.Threading;
using Nancy.Extensions;

namespace NancyApp
{
    public class FirstModule : NancyModule
    {
        public FirstModule()
        {
            Get["/"] = parameters => {
                return "fuck u";
            };

            Get["/testing"] = x =>
            {
                return View["staticview", this.Request.Url];
            };

            Get["/photo/{slug}"] = x =>
            {
                return String.Format(@"<h1>I'm sorry</h1><p>We're having some problems finding photo '{0}' for the moment.</p>", x.slug);
            };

            Get["/fileupload"] = x =>
            {
                var model = new Index() { Name = "Boss Hawg" };

                return View["FileUpload", model];
            };

            Post["/fileupload"] = x =>
            {
                var model = new Index() { Name = "Boss Hawg" };

                var file = this.Request.Files.FirstOrDefault();
                string fileDetails = "None";

                if (file != null)
                {
                    fileDetails = string.Format("{3} - {0} ({1}) {2}bytes", file.Name, file.ContentType, file.Value.Length, file.Key);
                }

                model.Posted = fileDetails;

                return View["FileUpload", model];
            };
        }
    }
}